
// Function.prototype.call = function (scope) {
//     scope = scope || window;
//     var args = [];
//     for (var i = 1; i < arguments.length; i++) {
//         var arg = arguments[i];
//         if (typeof arg === 'string') {
//             args.push('"' + arg + '"');
//         } else if (typeof arg === 'object') {
//             scope['arg' + i] = arg;
//             args.push('scope["arg' + i + '"]');
//         } else {
//             args.push(arg);
//         }
//     }

//     scope.fn = this;
//     var res = eval('scope.fn(' + args.join(',') + ')');
//     delete scope.fn;
//     for (var key in scope) {
//         if (key.startsWith('arg')) {
//             delete scope[key];
//         }
//     }
//     return res;
// };

Function.prototype.call = function(scope){
    var fn = this;
    var args = [].slice.apply(arguments);
    args.shift();
    return fn.apply(scope, args);
};

function Foo(age, sex, options) {
    console.log(this.name);
    console.log(age);
    console.log(sex);
    console.log(options)
    return 'abcdefg'
}
var res = Foo.call({ name: 'def' }, 45, 'man', { email: 'ss' });
console.log(res);